#!/bin/sh

# This shell script build FontForge

# source buildScripts/reSourceVersionEnvs
. buildScripts/reSourceVersionEnvs

echo ""
echo "-------------------------------------------------------------------"
echo "BUILDING FontForge (using CMake)"
echo "-------------------------------------------------------------------"
echo ""

set -ev

cd fontforge

mkdir build

cd build

cmake        		                        \
  -DCMAKE_BUILD_TYPE=Release                \
  -DCMAKE_INSTALL_PREFIX=$PDF2HTMLEX_PREFIX \
  -DBUILD_SHARED_LIBS:BOOL=OFF              \
  -DENABLE_GUI:BOOL=OFF                     \
  -DENABLE_X11:BOOL=OFF                     \
  -DENABLE_NATIVE_SCRIPTING:BOOL=ON         \
  -DENABLE_PYTHON_SCRIPTING:BOOL=OFF        \
  -DENABLE_PYTHON_EXTENSION:AUTO=OFF        \
  -DENABLE_LIBSPIRO:BOOL=OFF                \
  -DENABLE_LIBUNINAMESLIST:BOOL=OFF         \
  -DENABLE_LIBGIF:AUTO=OFF                  \
  -DENABLE_LIBJPEG:AUTO=ON                  \
  -DENABLE_LIBPNG:AUTO=ON                   \
  -DENABLE_LIBREADLINE:AUTO=OFF             \
  -DENABLE_LIBTIFF:AUTO=OFF                 \
  -DENABLE_WOFF2:AUTO=OFF                   \
  -DENABLE_DOCS:AUTO=OFF                    \
  -DENABLE_CODE_COVERAGE:BOOL=OFF           \
  -DENABLE_DEBUG_RAW_POINTS:BOOL=OFF        \
  -DENABLE_FONTFORGE_EXTRAS:BOOL=OFF        \
  -DENABLE_MAINTAINER_TOOLS:BOOL=OFF        \
  -DENABLE_TILE_PATH:BOOL=OFF               \
  -DENABLE_WRITE_PFM:BOOL=OFF               \
  -DENABLE_SANITIZER:ENUM="none"            \
  -DENABLE_FREETYPE_DEBUGGER:PATH=""        \
  -DSPHINX_USE_VENV:BOOL=OFF                \
  -DREAL_TYPE:ENUM="double"                 \
  -DTHEME:ENUM="tango"                      \
  ..

# Apply any patches required for fontforge raw sources before we make
#
#for APATCHFILE in $(ls ../patches/fontforge-$FONTFORGE_VERSION-*)
#do
#  echo "patching fontforge using [$APATCHFILE]" 
#  patch -p 1 < $APATCHFILE
#done

make $MAKE_PARALLEL

##########################################################
# FontForge CMakeLists.txt build options (2020/05/31):

# BUILD_SHARED_LIBS:BOOL=OFF       "Build libfontforge as a shared library")
# ENABLE_GUI:BOOL=OFF              "Build FontForge with GUI support")
# ENABLE_X11:BOOL=OFF              "Build the GUI using the X backend INSTEAD of the GDK backend" "ENABLE_GUI")
# ENABLE_NATIVE_SCRIPTING:BOOL=ON  "Enables FontForge's native scripting support")
# ENABLE_PYTHON_SCRIPTING:BOOL=OFF "Enables FontForge's Python scripting support")
# ENABLE_PYTHON_EXTENSION:AUTO=OFF "Builds the Python models for use with system python")
# ENABLE_LIBSPIRO:BOOL=ON          "Enables libspiro support")
# ENABLE_LIBUNINAMESLIST:BOOL=ON   "Enables libuninameslist support")
# ENABLE_LIBGIF:AUTO=OFF           "Enables GIF support")
# ENABLE_LIBJPEG:AUTO=ON           "Enables JPEG support")
# ENABLE_LIBPNG:AUTO=ON            "Enables PNG support")
# ENABLE_LIBREADLINE:AUTO=OFF      "Enables Readline support")
# ENABLE_LIBTIFF:AUTO=OFF          "Enables TIFF support")
# ENABLE_WOFF2:AUTO=OFF            "Enables WOFF2 support")
# ENABLE_DOCS:AUTO=OFF             "Enables building and installing documentation. Sphinx is required to build it.")
# ENABLE_CODE_COVERAGE:BOOL=OFF    "Build with code coverage support")
# ENABLE_DEBUG_RAW_POINTS:BOOL=OFF "Add a raw mode to the points window of the debugger")
# ENABLE_FONTFORGE_EXTRAS:BOOL=OFF "Builds programs from the contrib directory")
# ENABLE_MAINTAINER_TOOLS:BOOL=OFF "Build programs normally only used by FontForge maintainers and developers")
# ENABLE_TILE_PATH:BOOL=OFF        "Enable a 'tile path' command (a variant of 'expand stroke')")
# ENABLE_WRITE_PFM:BOOL=OFF        "Add the ability to save a PFM file without creating the associated font file")
# ENABLE_SANITIZER:ENUM="none"     "Enables a sanitizer. Requires support from the compiler."
# ENABLE_FREETYPE_DEBUGGER:PATH="" "Use FreeTypes internal debugger within FontForge."
# SPHINX_USE_VENV:BOOL=OFF         "If building documentation and Sphinx is not installed, try to install and use it from a python3 venv."
# REAL_TYPE:ENUM="double"          "Sets the floating point type used." "double" "float")
# THEME:ENUM="tango"               "Sets the GUI theme." "tango" "2012")

